package com.yuan.java.java.util;

import org.junit.Test;

import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * @author yuaneg 2019/1/7
 */
public class TestTest {

    @Test
    public void stringJoiner() {
        StringJoiner stringJoiner = new StringJoiner(",", "[", "]");
        stringJoiner.add("你").add("好");
        System.out.println(stringJoiner.toString());
    }


    /**
     * 做 缓存用的
     */
    @Test
    public void weakHashMap() {
        WeakHashMap<String, Object> weakHashMap = new WeakHashMap<>();
        weakHashMap.put(null, null);
        // size == 1
        System.out.println(weakHashMap.size());
        System.out.println(weakHashMap.size());
    }

    @Test
    public void timezone() {
        Arrays.asList(TimeZone.getAvailableIDs()).forEach(System.out::println);
        System.out.println(TimeZone.getTimeZone("Asia/Shanghai"));
        System.out.println(TimeZone.getDefault());
    }

    @Test
    public void timertest() throws InterruptedException {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            public void run() {
                System.out.println("11232");
            }
        }, 200, 1000);
        TimeUnit.SECONDS.sleep(2);
    }


    @Test
    public void stringtoken() {
        String s = "This is a test string";
        StringTokenizer st = new StringTokenizer(s, " ");
        System.out.println("Token Total: " + st.countTokens());
        while (st.hasMoreElements()) {
            System.out.println(st.nextToken());
        }
    }

    @Test
    public void random() {
        //取得一组 随机数字
        SplittableRandom splittableRandom = new SplittableRandom();
        splittableRandom.doubles().limit(10).forEach(System.out::println);
    }

    @Test
    public void serviceLoader() {
        //在实现类的jar包的META-INF下新建一个文件夹services，并在services下新建一个文件，以接口的全限定名为文件名，内容为实现类的全限定名。
        ServiceLoader<A> serviceLoader =  ServiceLoader.load(A.class);
        serviceLoader.forEach(A::say);
    }


}
